package com.example.demo.offer;

import java.util.HashSet;
import java.util.Set;

public class Offer23 {
    public static void main(String[] args) {

    }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        Set<ListNode> set = new HashSet<>();
        ListNode cur = headA;
        while (cur != null){
            set.add(cur);
            cur = cur.next;
        }
        cur = headB;
        while (cur != null){
            if(set.contains(cur)){
                return cur;
            }
            cur = cur.next;
        }
        return null;
    }
}
